package com.fr.privilege.ui;

import com.fr.base.StringUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.core.util.TemplateUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.web.core.WebUtils;
import com.fr.web.platform.PlatformUtils;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class CustomLogioutUI extends LoginoutUI
{
  private String loginPath = "";

  public String getLoginPath()
  {
    return this.loginPath;
  }

  public void setLoginPath(String paramString)
  {
    this.loginPath = paramString;
  }

  public void redirect2LoginUI(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse, String paramString)
    throws Exception
  {
    PlatformUtils.redirect(paramHttpServletResponse, createURL(paramHttpServletRequest, paramHttpServletResponse, paramString));
  }

  public String createURL(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse, String paramString)
    throws Exception
  {
    HttpSession localHttpSession = paramHttpServletRequest.getSession(true);
    Map localMap = WebUtils.createTemplateMap(paramHttpServletRequest);
    localMap.put("reportlet", this.loginPath);
    String str1 = null;
    if (this.loginPath.endsWith(".cpt"))
      str1 = TemplateUtils.render("${servletURL}?reportlet=${reportlet}&op=form", localMap);
    else
      str1 = this.loginPath;
    String str2 = WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "reportlet");
    String str3 = WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "op");
    if ((!(ComparatorUtils.equals(str2, this.loginPath))) && (!(ComparatorUtils.equals(str3, "auth_logout"))))
      localHttpSession.setAttribute("fr_from", WebUtils.getOriginalURL(paramHttpServletRequest));
    if (StringUtils.isNotEmpty(paramString))
      localHttpSession.setAttribute("fr_error", paramString);
    str1 = str1 + "&_=" + System.currentTimeMillis();
    return str1;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if (str.equals("LoginPath"))
        this.loginPath = paramXMLableReader.getAttr("path");
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    if (StringUtils.isNotEmpty(this.loginPath))
    {
      paramXMLPrintWriter.startTAG("LoginPath").attr("path", this.loginPath);
      paramXMLPrintWriter.end();
    }
  }

  public void readJSON(JSONObject paramJSONObject)
    throws JSONException
  {
    super.readJSON(paramJSONObject);
    setLoginPath(paramJSONObject.getString("loginpath"));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    return super.clone();
  }
}